package com.crawler.webhook;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.crawler.common.WebhookConstant;
import com.dingtalk.chatbot.DingtalkChatbotClient;
import com.dingtalk.chatbot.message.TextMessage;

/**
 * 通知
 * @author rubekid
 *
 * 2017年9月30日 上午9:57:58
 */
public class Notify {

	public static final Logger LOGGER = LoggerFactory.getLogger(Notify.class);

	/**
	 * 发送消息
	 * @param user
	 * @param message
	 */
	public static void debug(String message){
		if(WebhookConstant.WEBHOOK != null && WebhookConstant.DEBUG){			
			send(message, WebhookConstant.WEBHOOK);
		}
	}
	
	/**
	 * 发送消息
	 * @param user
	 * @param message
	 */
	public static void send(String content, String webhook){
		try{
			content = "【"+ WebhookConstant.APP_NAME +"】:" + content;
			TextMessage message = new TextMessage(content);
			DingtalkChatbotClient client = new DingtalkChatbotClient();
	        client.send(webhook, message);
		}
		catch(Exception ex){
			LOGGER.error(ex.getMessage(), ex);
		}
	}
	
}